package com.naiterui.ehp.bs.doctor.dao.mongo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.ehp.bs.doctor.prodocl.BannerRead;

@Repository
public class AdBannerReadDao extends MongoBaseDao {

    private static final String COLLECTION_NAME = "m_bannr_read";

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    protected MongoTemplate getMongoTemplate() {
        return mongoTemplate;
    }

    /**
     * 添加banner阅读数
     *
     * @param bannerRead
     */
    public void save(BannerRead bannerRead) {
        super.save(bannerRead, COLLECTION_NAME);
    }

    /**
     * BannerReadDao.getBannerByConditions()
     *
     * @param doctorId
     * @param bannerId
     *
     * @return
     *
     * @Author YongYang
     * @Date 2016年6月24日
     * @since 1.0.0
     */
    public BannerRead getBannerByConditions(long doctorId, long bannerId) {
        Criteria criteria = Criteria.where("doctorId").is(doctorId).and("bannerId").is(bannerId);
        Query query = Query.query(criteria);
        List<BannerRead> results = super.find(query, BannerRead.class, COLLECTION_NAME);
        return results.size() > 0 ? results.get(0) : null;
    }
}
